<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
    <title>Zend_Config_Json - Zend Framework Manual</title>

    <link href="../css/shCore.css" rel="stylesheet" type="text/css" />
    <link href="../css/shThemeDefault.css" rel="stylesheet" type="text/css" />
    <link href="../css/styles.css" media="all" rel="stylesheet" type="text/css" />
</head>
<body>
<h1>Zend Framework</h1>
<h2>Programmer's Reference Guide</h2>
<ul>
    <li><a href="../en/zend.config.adapters.json.html">Inglês (English)</a></li>
    <li><a href="../pt-br/zend.config.adapters.json.html">Português Brasileiro (Brazilian Portuguese)</a></li>
</ul>
<table width="100%">
    <tr valign="top">
        <td width="85%">
            <table width="100%">
                <tr>
                    <td width="25%" style="text-align: left;">
                    <a href="zend.config.adapters.ini.html">Zend_Config_Ini</a>
                    </td>

                    <td width="50%" style="text-align: center;">
                        <div class="up"><span class="up"><a href="zend.config.html">Zend_Config</a></span><br />
                        <span class="home"><a href="manual.html">Guia de Refer&ecirc;ncia do Programador</a></span></div>
                    </td>

                    <td width="25%" style="text-align: right;">
                        <div class="next" style="text-align: right; float: right;"><a href="zend.config.adapters.xml.html">Zend_Config_Xml</a></div>
                    </td>
                </tr>
            </table>
<hr />
<div id="zend.config.adapters.json" class="section"><div class="info"><h1 class="title">Zend_Config_Json</h1></div>
    

    <div class="section" id="zend.config.adapters.json.intro"><div class="info"><h1 class="title">Overview</h1></div>
        

        <p class="para">
            <a href="http://www.json.org/" class="link external">&raquo; JSON</a> is an acronym for &quot;JavaScript Object
            Notation&quot;; while compatible with JavaScript, it is also intended as a general-purpose,
            cross-language data interchange format.  <span class="classname">Zend_Config_Json</span> is a
            lightweight <span class="classname">Zend_Config</span> extension using <acronym class="acronym">JSON</acronym>
            as its serialization format.
        </p>
    </div>

    <div class="section" id="zend.config.adapters.json.quick-start"><div class="info"><h1 class="title">Quick Start</h1></div>
        

        <p class="para">
            The following is a <acronym class="acronym">JSON</acronym> version of a standard application configuration.
        </p>

        <pre class="programlisting brush: json">
{
    &quot;production&quot;:{
        &quot;phpSettings&quot;:{
            &quot;display_startup_errors&quot;: false,
            &quot;display_errors&quot;: false
        },
        &quot;includePaths&quot;:{
            &quot;library&quot;: &quot;APPLICATION_PATH/../library&quot;
        },
        &quot;bootstrap&quot;:{
            &quot;path&quot;: &quot;APPLICATION_PATH/Bootstrap.php&quot;,
            &quot;class&quot;: &quot;Bootstrap&quot;
        },
        &quot;appnamespace&quot;: &quot;Application&quot;,,
        &quot;resources&quot;:{
            &quot;frontController&quot;:{
                &quot;controllerDirectory&quot;: &quot;APPLICATION_PATH/controllers&quot;,
                &quot;moduleDirectory&quot;: &quot;APPLICATION_PATH/modules&quot;,
                &quot;params&quot;:{
                    &quot;displayExceptions&quot;: false
                }
            },
            &quot;modules&quot;:[],
            &quot;db&quot;:{
                &quot;adapter&quot;: &quot;pdo_sqlite&quot;,
                &quot;params&quot;:{
                    &quot;dbname&quot;: &quot;APPLICATION_PATH/../data/db/application.db&quot;
                }
            },
            &quot;layout&quot;:{
                &quot;layoutPath&quot;: &quot;APPLICATION_PATH/layouts/scripts/&quot;
            }
        }
    },
    &quot;staging&quot;:{
        &quot;_extends&quot;: &quot;production&quot;
    },
    &quot;testing&quot;:{
        &quot;_extends&quot;: &quot;production&quot;,
        &quot;phpSettings&quot;:{
            &quot;display_startup_errors&quot;: true,
            &quot;display_errors&quot;: true
        },
    },
    &quot;development&quot;:{
        &quot;_extends&quot;: &quot;production&quot;,
        &quot;phpSettings&quot;:{
            &quot;display_startup_errors&quot;: true,
            &quot;display_errors&quot;: true
        },
        &quot;resources&quot;:{
            &quot;frontController&quot;:{
                &quot;params&quot;:{
                    &quot;displayExceptions&quot;: true
                }
            }
        }
    }
}
</pre>


        <p class="para">
            To utilize it, you simply instantiate <span class="classname">Zend_Config_Json</span>, pointing
            it to the location of this file and indicating the section of the file to load. By
            default, constant names found in values will be substituted with their appropriate
            values.
        </p>

        <pre class="programlisting brush: php">
$config = new Zend_Config_Json(
    APPLICATION_PATH . &#039;/configs/application.json&#039;,
    APPLICATION_ENV
);
</pre>


        <p class="para">
            Once instantiated, you use it as you would any other configuration object.
        </p>

        <pre class="programlisting brush: php">
$db = Zend_Db::factory($config-&gt;resources-&gt;db);
</pre>


        <div class="warning"><b class="warning">Warning</b><div class="info"><h1 class="title">Use Constants With Care</h1></div>
            

            <p class="para">
                <acronym class="acronym">JSON</acronym> has a strict structure with regards to data types. As such,
                you need to ensure that your constants are use correctly. For constants that have
                string values, put your constant values in double quotes (&quot;&quot;). For non-string
                values, you can omit the quotes -- but be absolutely certain that they are not
                returning strings, as otherwise you will encounter parser errors with your
                configuration file. When in doubt, enclose the contant in double quotes.
            </p>
        </div>
    </div>

    <div class="section" id="zend.config.adapters.json.options"><div class="info"><h1 class="title">Configuration Options</h1></div>
        

        <p class="para">
            The following options may be passed as keys to the third, <var class="varname">$options</var>
            argument of the constructor.
        </p>

        <dl>
<div class="info"><h1 class="title">Zend_Config_Json Options</h1></div>
            

            <dt>

                <dt class="term">allow_modifications/allowModifications</dt>

                <dd>

                    <p class="para">
                        The default behavior of <span class="classname">Zend_Config</span> is to mark the
                        object as immutable once loaded. Passing this flag with a boolean
                        <b><tt>true</tt></b> will enable modifications to the object.
                    </p>
                </dd>

            </dt>


            <dt>

                <dt class="term">skip_extends/skipExtends</dt>

                <dd>

                    <p class="para">
                        By default, any time a section extends another,
                        <span class="classname">Zend_Config</span> will merge the section with the section
                        it extends. Speciying a boolean <b><tt>true</tt></b> value to this
                        option will disable this feature, giving you only the configuration defined
                        explicitly in that section.
                    </p>
                </dd>

            </dt>


            <dt>

                <dt class="term">ignore_constants</dt>

                <dd>

                    <p class="para">
                        By default, <span class="classname">Zend_Config_Json</span> will replace constant
                        names found in values with the defined constant value. You map pass a
                        boolean <b><tt>true</tt></b> to this option to disable this
                        functionality.
                    </p>

                    <p class="para">
                        Please note that ignoring constants can potentially lead to parse errors,
                        particularly if you are using constants for integer, float, or boolean
                        values. The safest practice is to enclose constants within quotes.
                    </p>
                </dd>

            </dt>

        </dl>

    </div>

    <div class="section" id="zend.config.adapters.json.methods"><div class="info"><h1 class="title">Available Methods</h1></div>
        

        <dl>

            <dt id="zend.config.adapters.json.methods.constructor">
                <dt class="term">
                    <div class="methodsynopsis dc-description">
                         <span class="methodname">__construct</span>
                        <span class="methodparam">( 
                            <code_funcparams class="funcparams">$json, $section = null, $options = false</code_funcparams>
                         )</span>
                    </div>

                </dt>

                <dd>

                    <p class="para">
                        Constructor. <var class="varname">$json</var> should be either a valid
                        <acronym class="acronym">JSON</acronym> string, or refer to a valid filesystem location
                        containing a <acronym class="acronym">JSON</acronym> configuration file.
                        <var class="varname">$section</var>, if specified, indicates a specific section of
                        the configuration file to use.  <var class="varname">$options</var> is discussed in
                        the <a href="zend.config.adapters.json.html#zend.config.adapters.json.options" class="link">options
                            section</a>.
                    </p>
                </dd>

            </dt>


            <dt id="zend.config.adapters.json.methods.set-ignore-constants">
                <dt class="term">
                    <div class="methodsynopsis dc-description">
                         <span class="methodname">setIgnoreConstants</span>
                        <span class="methodparam">( 
                            <code_funcparams class="funcparams">$flag</code_funcparams>
                         )</span>
                    </div>

                </dt>

                <dd>

                    <p class="para">
                        This <em class="emphasis">static</em> function may be used to globally override
                        the default settings for how constants found in <acronym class="acronym">JSON</acronym>
                        strings are handled. By default, constant names are replaced with the
                        appropriate constant values; passing a boolean <b><tt>true</tt></b>
                        value to this method will override that behavior. (You can override it
                        per-instance via the <var class="varname">ignore_constants</var> option as well.)
                    </p>
                </dd>

            </dt>


            <dt id="zend.config.adapters.json.methods.ignore-constants">
                <dt class="term">
                    <div class="methodsynopsis dc-description">
                         <span class="methodname">ignoreConstants</span>
                        <span class="methodparam">( 
                            <code_funcparams class="funcparams"/>
                         )</span>
                    </div>

                </dt>

                <dd>

                    <p class="para">
                        This <em class="emphasis">static</em> method gives you the current setting for
                        the <var class="varname">ignore_constants</var> flag.
                    </p>
                </dd>

            </dt>

        </dl>

    </div>
</div>
        <hr />

            <table width="100%">
                <tr>
                    <td width="25%" style="text-align: left;">
                    <a href="zend.config.adapters.ini.html">Zend_Config_Ini</a>
                    </td>

                    <td width="50%" style="text-align: center;">
                        <div class="up"><span class="up"><a href="zend.config.html">Zend_Config</a></span><br />
                        <span class="home"><a href="manual.html">Guia de Refer&ecirc;ncia do Programador</a></span></div>
                    </td>

                    <td width="25%" style="text-align: right;">
                        <div class="next" style="text-align: right; float: right;"><a href="zend.config.adapters.xml.html">Zend_Config_Xml</a></div>
                    </td>
                </tr>
            </table>
</td>
        <td style="font-size: smaller;" width="15%"> <style type="text/css">
#leftbar {
	float: left;
	width: 186px;
	padding: 5px;
	font-size: smaller;
}
ul.toc {
	margin: 0px 5px 5px 5px;
	padding: 0px;
}
ul.toc li {
	font-size: 85%;
	margin: 1px 0 1px 1px;
	padding: 1px 0 1px 11px;
	list-style-type: none;
	background-repeat: no-repeat;
	background-position: center left;
}
ul.toc li.header {
	font-size: 115%;
	padding: 5px 0px 5px 11px;
	border-bottom: 1px solid #cccccc;
	margin-bottom: 5px;
}
ul.toc li.active {
	font-weight: bold;
}
ul.toc li a {
	text-decoration: none;
}
ul.toc li a:hover {
	text-decoration: underline;
}
</style>
 <ul class="toc">
  <li class="header home"><a href="manual.html">Guia de Refer&ecirc;ncia do Programador</a></li>
  <li class="header up"><a href="manual.html">Guia de Refer&ecirc;ncia do Programador</a></li>
  <li class="header up"><a href="reference.html">Refer&ecirc;ncia do Zend Framework</a></li>
  <li class="header up"><a href="zend.config.html">Zend_Config</a></li>
  <li><a href="zend.config.introduction.html">Introdu&ccedil;&atilde;o</a></li>
  <li><a href="zend.config.theory_of_operation.html">Teoria de Opera&ccedil;&atilde;o</a></li>
  <li><a href="zend.config.adapters.ini.html">Zend_Config_Ini</a></li>
  <li class="active"><a href="zend.config.adapters.json.html">Zend_Config_Json</a></li>
  <li><a href="zend.config.adapters.xml.html">Zend_Config_Xml</a></li>
  <li><a href="zend.config.adapters.yaml.html">Zend_Config_Yaml</a></li>
 </ul>
 </td>
    </tr>
</table>

<script type="text/javascript" src="../js/shCore.js"></script>
<script type="text/javascript" src="../js/shAutoloader.js"></script>
<script type="text/javascript" src="../js/main.js"></script>

</body>
</html>